package com.yuyang.wifi.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuyang.wifi.R;
import com.yuyang.wifi.activitys.mine.AppContants;
import com.yuyang.wifi.model.WifiBean;
import com.yuyang.wifi.views.recyclerview.base.BaseQuickAdapter;
import com.yuyang.wifi.views.recyclerview.base.BaseViewHolder;

import java.util.List;


public class NewWifiListAdapter extends BaseQuickAdapter<WifiBean> {

    private Context mContext;
    private List<WifiBean> resultList;

    public NewWifiListAdapter(Context context, List<WifiBean> resultList) {
        super(R.layout.item_contract_wifi_list_layout, resultList);
        this.mContext = context;
        this.mContext = context;
        this.resultList = resultList;
    }

    @Override
    protected void convert(BaseViewHolder helper, WifiBean msg) {
        TextView tv_wifi_name = helper.getView(R.id.tv_wifi_name);
        ImageView iv_wifi_sign_in = helper.getView(R.id.iv_wifi_sign_in);
        ImageView iv_lock = helper.getView(R.id.iv_lock);

        int position = helper.getAdapterPosition();
        final WifiBean bean = resultList.get(position);

        tv_wifi_name.setText(bean.getWifiName());

        //可以传递给adapter的数据都是经过处理的，已连接或者正在连接状态的wifi都是处于集合中的首位，所以可以写出如下判断
        if (position == 0 && (AppContants.WIFI_STATE_ON_CONNECTING.equals(bean.getState()) || AppContants.WIFI_STATE_CONNECT.equals(bean.getState()))) {
            helper.setTextColor(R.id.tv_wifi_name, mContext.getResources().getColor(R.color.black_000000));
            helper.setText(R.id.tv_wifi_state, bean.getState());
        } else {
            helper.setTextColor(R.id.tv_wifi_name, mContext.getResources().getColor(R.color.text_505352));
            helper.setText(R.id.tv_wifi_state, bean.getState());
        }

        String level = bean.getLevel();
        switch (level) {
            case "1":
                iv_wifi_sign_in.setBackgroundResource(R.mipmap.icon_wifi_fill);
                break;
            case "2":
                iv_wifi_sign_in.setBackgroundResource(R.mipmap.icon_wifi_center);
                break;
            case "3":
                iv_wifi_sign_in.setBackgroundResource(R.mipmap.icon_wifi_low);
                break;
        }

//        boolean jm = bean.isJM();
//        if (jm) {
//            iv_lock.setVisibility(View.VISIBLE);
//        } else {
//            iv_lock.setVisibility(View.GONE);
//        }
    }
}
